package com.ss.android.common.ui.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.widget.FrameLayout;

import com.bytedance.common.utility.UIUtils;

public class SwipeOverlayFrameLayout extends FrameLayout {
    public interface OnSwipeBackListener {
        boolean onSwipeBack();

        boolean b();
    }

    OnSwipeBackListener mOnSwipeBackListener;
    float b;
    float c;
    private GestureDetector d;
    private boolean e;
    private boolean f;
    private boolean g;

    public SwipeOverlayFrameLayout(Context arg3) {
        super(arg3);
        this.e = true;
        this.f = false;
        this.g = false;
        this.a(arg3);
    }

    public SwipeOverlayFrameLayout(Context arg3, AttributeSet arg4) {
        super(arg3, arg4);
        this.e = true;
        this.f = false;
        this.g = false;
        this.a(arg3);
    }

    public SwipeOverlayFrameLayout(Context arg3, AttributeSet arg4, int arg5) {
        super(arg3, arg4, arg5);
        this.e = true;
        this.f = false;
        this.g = false;
        this.a(arg3);
    }

    private void a(Context arg4) {
        GestureDetector.SimpleOnGestureListener simpleOnGestureListener = new GestureDetector.SimpleOnGestureListener() {

            public final boolean onFling(MotionEvent arg9, MotionEvent arg10, float arg11, float arg12) {
                boolean v0 = false;
                if (SwipeOverlayFrameLayout.this.mOnSwipeBackListener != null
                        && Math.abs(arg10.getY() - arg9.getY()) <= SwipeOverlayFrameLayout.this.b) {
                    float v2 = Math.abs(arg11);
                    float v3 = Math.abs(arg12);
                    float v4 = Math.abs(arg10.getX() - arg9.getX());
                    float v5 = Math.abs(arg10.getY() - arg9.getY());
                    if (v3 < v2 && v5 < v4 && v4 > SwipeOverlayFrameLayout.this.c) {
                        if (arg11 > 0f) {
                            v0 = SwipeOverlayFrameLayout.this.mOnSwipeBackListener.onSwipeBack();
                        } else if (arg11 < 0f) {
                            v0 = SwipeOverlayFrameLayout.this.mOnSwipeBackListener.b();
                        }
                    }
                }

                return v0;
            }
        };
        this.b = UIUtils.dp2px(arg4, 45f);
        this.c = UIUtils.dp2px(arg4, 65f);
        this.d = new GestureDetector(arg4.getApplicationContext(), simpleOnGestureListener);
        this.d.setOnDoubleTapListener(null);
        this.d.setIsLongpressEnabled(false);
    }

    public boolean dispatchTouchEvent(MotionEvent arg4) {
        int v1 = 0;
        boolean v0 = true;
        try {
            if (arg4.getAction() == 0) {
                this.g = false;
            }

            if ((this.g) && (this.f)) {
                v1 = 1;
            }

            if ((this.e) && this.d != null && v1 == 0 && (this.d.onTouchEvent(arg4))) {
                arg4.setAction(3);
                super.dispatchTouchEvent(arg4);
                return v0;
            }

            v0 = super.dispatchTouchEvent(arg4);
        } catch (Exception v1_1) {
        }

        return v0;
    }

    public void requestDisallowInterceptTouchEvent(boolean arg1) {
        super.requestDisallowInterceptTouchEvent(arg1);
        this.g = arg1;
    }

    public void setDisllowInterceptEnabled(boolean arg1) {
        this.f = arg1;
    }

    public void setOnSwipeListener(OnSwipeBackListener arg1) {
        this.mOnSwipeBackListener = arg1;
    }

    public void setSwipeEnabled(boolean arg1) {
        this.e = arg1;
    }
}

